#!/usr/bin/ruby
require 'mathn'

class Integer
  def prime?
    max = Math.sqrt(self).ceil
    max -= 1 if max % 2 == 0
    pgen = Prime.new
    pgen.each do |factor|
      return false if self % factor == 0
      return true if factor > max
    end
  end
end


def smaller_prime(n)
  begin
    return n if n.prime?
    n = n - 1
  end while n > 0
end

list = []
min = 4
max = 30
min.upto(max) do |n|
  list << smaller_prime(2**n)
end
puts("{" + list.join(", ") + "}")
puts("primes = " + (max - min + 1).to_s)
